package com.ultrasoft.farmasoft.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ultrasoft.farmasoft.domain.Country;
import com.ultrasoft.farmasoft.domain.Region;
import com.ultrasoft.farmasoft.domain.Locality;
import com.ultrasoft.farmasoft.repository.CountryDao;
import com.ultrasoft.farmasoft.repository.RegionDao;
import com.ultrasoft.farmasoft.repository.LocalityDao;

@Service
public class GeneralAdministrationSeviceImpl implements GeneralAdministrationService {
	
	private CountryDao countryDao;
	private RegionDao regionDao;
	private LocalityDao localityDao;
	
	//COUNTRY
	@Autowired
    public GeneralAdministrationSeviceImpl(CountryDao countryDao, RegionDao regionDao, LocalityDao  localityDao){
        this.countryDao 					= countryDao;
        this.regionDao						= regionDao;
        this.localityDao					= localityDao;
    }
	
    @Transactional(readOnly = true)    
	public List<Country> geCountries(){
		return countryDao.getCountryList();
	}
    @Transactional
    public void removeCountry(Country country){
    	countryDao.remove(country);
    }    
    @Transactional
    public void addCountry(Country country){
    	countryDao.add(country);
    }
	// start Country
    @Transactional(readOnly = true)
    public List<Country> getCountryList(){
		return countryDao.getCountryList();
	}	
    public List<Country> getCountryListWithIDCountry(Short idCountry){
		return countryDao.getCountryListWithIDCountry(idCountry);		
    }
	
    @Transactional(readOnly = true)
    public Country searchCountryByID(Short idCountry){
    	return countryDao.findCountryByID(idCountry);
    }

	public void updateCountry(Country country) {
		countryDao.update(country);
	} 
	public List<Country> getCountryList(Short idCountry) {
		return countryDao.getCountryListWithIDCountry(idCountry);
	}
	//end Country
	
	//REGION
	// start Region
	@Transactional(readOnly = true)
    public List<Region> getRegionList(){
		return regionDao.getRegionList();
	}
    @Transactional(readOnly = true)
    public List<Region> getRegionList(short idCountry){
    	return regionDao.getRegionList(idCountry);	
    }
    @Transactional(readOnly = true)
    public List<Region> getRegionList(short idCountry,boolean active){
    	return regionDao.getRegionList(idCountry,active);	
    }
    @Transactional(readOnly = true)
    public Region searchRegionByRegionId(Integer regionId){
    	return regionDao.findRegionByRegionId(regionId);
    }
    @Transactional
    public void addRegion(Region region){
    	regionDao.add(region);
    }
    @Transactional
    public void updateRegion(Region region){
    	regionDao.update(region);
    }  
    @Transactional
    public void removeRegion(Region region){
    	regionDao.remove(region);
    }
    // end region

	//LOCALITY
    //start locality  
    @Transactional(readOnly = true)
    public List<Locality> getLocality(){
		return localityDao.getLocality();
	}
    @Transactional(readOnly = true)
	public List<Locality> getLocalityListByRegionIdByActive(Integer idRegion,boolean active){
		return localityDao.getLocalityListByRegionIdByActive(idRegion, active);
	}
    @Transactional
	public void addLocality(Locality locality){
		localityDao.add(locality);
	}
    @Transactional
	public void updateLocality(Locality locality) {
		localityDao.update(locality);
	}

    @Transactional
   	public void removeLocality(Locality locality) {
    	localityDao.remove(locality);
   	}
  
	@Transactional(readOnly = true)
	public Locality searchLocalityByRegionIdByLocalityId(Integer regionId ,short localityId) {
	    return localityDao.findLocalityByRegionIdByLocalityId(regionId, localityId);
	}
	@Transactional(readOnly = true)
	public short getLocalityIdMax(Integer regionId){
		return localityDao.getLocalityIdMax(regionId);
	}
	//end Locality
}

